package com.xp.code.dwr;

import java.util.Random;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import com.xp.code.services.ILoginInfoService;
import com.xp.code.util.DWRLoginResult;
import com.xp.code.util.XPCodeSession;
import com.xp.code.vo.LoginInfoVO;

/**
 * 
 * @author HAHA
 * 
 */
@Component("AuthServices")
public class AuthServices {

	private static Logger loger=Logger.getLogger(AuthServices.class);
	@Resource(name="loginInfoService")
	private ILoginInfoService loginInfoService;
	public AuthServices() {

	}

	
	public ILoginInfoService getLoginInfoService() {
		return loginInfoService;
	}


	public void setLoginInfoService(ILoginInfoService loginInfoService) {
		this.loginInfoService = loginInfoService;
	}


	public DWRLoginResult validateLogin(String userCode, String userPasswd) {
		DWRLoginResult result = new DWRLoginResult();
		LoginInfoVO loginInfoEntity=this.loginInfoService.validateLogin(userCode, userPasswd);
		result.setLoginCode(loginInfoEntity.getLoginCode());
		result.setLoginMsg(loginInfoEntity.getLoginMsg());
		/*Random ints = new Random();
		if (ints.nextInt() % 2 == 0) {
			result.setLoginCode("0");
			result.setLoginMsg("0");
			loger.warn("登录成功");
		} else {
			result.setLoginCode("-1");
			result.setLoginMsg("密码过期");
			loger.warn("登录失败");
		}*/
		return result;
	}

}
